export default {
  namespaced: true,

  //数据节点
  state: {
    address: JSON.parse(uni.getStorageSync('address') || '{}'),
    token: uni.getStorageSync('token') || '',
    //用户的信息对象
    userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
    //重定向的对象
    redirectInfo: null
  },
  //方法节点
  mutations: {
    //更新收货地址
    updateAddress(state, address) {
      state.address = address
      this.commit('my_user/saveAddressToStorage')
    },
    //持久化存储地址
    saveAddressToStorage(state) {
      uni.setStorageSync('address', JSON.stringify(state.address))
    },
    //更新用户信息
    updateUserInfo(state, userinfo) {
      state.userinfo = userinfo
      this.commit('my_user/saveUserInfoToStorage')
    },
    //持久化存储用户信息
    saveUserInfoToStorage(state) {
      uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
    },
    //更新token
    updateToken(state, token) {
      state.token = token
      this.commit('my_user/saveTokenToStorage')
    },
    //持久化token
    saveTokenToStorage(state) {
      uni.setStorageSync('token', state.token)
    },
    //更新重定向
    updateRedirectInfo(state, infoObject) {
      state.redirectInfo = infoObject
    }
  },
  getters: {
    addstr(state) {
      if (!state.address.provinceName) return ''
      return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
  }
}